// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import JsEncrypt from 'jsencrypt'
import qs from 'qs'
import cookies from 'vue-cookies'

import JsonViewer from "vue-json-viewer";

import layui from "./assets/import/layui"
import common from './assets/common/common'
import layui_common from './assets/common/layui_common'
import common_config from './assets/common/config'

axios.defaults.withCredentials = true
axios.defaults.timeout = 600000


Vue.config.productionTip = false
Vue.prototype.$axios = axios
Vue.prototype.$qs = qs
Vue.prototype.$jsEncrypt = JsEncrypt
Vue.prototype.$cookies = cookies; //配置时候prototype.$这里的名字自己定义不是固定是cookies

Vue.use(JsonViewer);
Vue.use(common);
Vue.use(common_config);
Vue.use(layui);
Vue.use(layui_common); //配置layui公共js




/* eslint-disable no-new */
router.beforeEach(function(to, from, next) {
    document.title = to.meta.title || '';
    console.log(to.fullPath);
    if (to.meta.login) {
        if (window.sessionStorage.token) {
            if (to.fullPath == "/") {
                next("/manager/index");
            } else {
                next();
            }
        } else {
            next("/login");
        }
    } else {
        if (to.fullPath == "/") {
            next("/manager/index");
        } else {
            next();
        }
    }
})

new Vue({
    el: '#app',
    mode: 'history',
    router,
    components: { App },
    template: '<App/>',
})